#!/usr/local/bin/python3
# -*- coding: UTF-8 -*-
"""
@author:apple
@file:demo_dict.py
@time:2021/05/28
### dict
- 造字典的四种方式
- 字典的key必须是可hash的，同时唯一
- 字典删除
- [key] 与 get(key) 的区别
- setdefault
"""


def init_dict():
    ...
    p1 = {'name':'wangwu','age':21};
    p2 = dict(name='li',age = 2);
    p3 = dict([('name','zhangsan'),['age',21]])
    p4 = dict.fromkeys(['name', 'age'])
    print(p1,p2,p3,p4)

def key_uniq():
    ...
    n1 = {'k1':'21','k2':'op'}
    n1.pop('k2')
    print(n1)
    # print(n1['lo'])
    print(n1.get('lo'))
    # setdefault 没有对应的key就设置，有对应key什么都不做
    n1.setdefault('k3','456')
    print(n1)

if __name__ == '__main__':
    pass
    # init_dict()
    key_uniq()